package com.ikas.ai.handle;

/**
 * json返回对象类型
 * @author HXH
 */
@SuppressWarnings("all")
public enum JsonResultType {

    // OK
    OK(200),

    // Bad Request
    REDIRECTREQUEST(301),

    // Bad Request
    BADREQUEST(400),

    // Unauthorized
    UNAUTHORIZED(401),

    // Not Found
    NOTFOUND(404),

    // Request Time-out
    REQUESTTIMEOUT(408),

    // Internal Server Error
    INTERNALSERVERERROR(500),

    // 错误
    ERROR(1000),

    // 错误
    INVALIDPARAM(1001),

    // 处理超时
    TIMEOUT(1002),

    // SESSION过期
    SESSIONTIMEOUT(1003),

    // 访问失败
    ACCESSFAILURE(1004),

    // 没有登录
    NOLOGIN(1005),

    // 锁定
    LOCK(1006),

    //任务终止
    TERMINATED(1007);

    private int value;

    /**
     * 获取枚举值
     *
     * @return
     */
    public int getValue() {
        return value;
    }

    /**
     * 构造函数
     *
     * @param value
     */
    JsonResultType(int value) {
        this.value = value;
    }

    /**
     * 整形转换为枚举
     *
     * @param value 整形值
     * @return 枚举值
     */
    public static JsonResultType parse(int value) {
        JsonResultType rtn;
        switch (value) {
            case 200:
                rtn = OK;
                break;
            case 400:
                rtn = BADREQUEST;
                break;
            case 401:
                rtn = NOTFOUND;
                break;
            case 408:
                rtn = REQUESTTIMEOUT;
                break;
            case 500:
                rtn = INTERNALSERVERERROR;
                break;
            case 1001:
                rtn = INVALIDPARAM;
                break;
            case 1002:
                rtn = TIMEOUT;
                break;
            case 1003:
                rtn = SESSIONTIMEOUT;
                break;
            case 1004:
                rtn = ACCESSFAILURE;
                break;
            case 1005:
                rtn = NOLOGIN;
                break;
            case 1006:
                rtn = LOCK;
                break;
            case 1007:
                rtn = TERMINATED;
                break;
            default:
                rtn = ERROR;
        }
        return rtn;
    }
}
